<route lang="json5" type="page">
{
  style: {
    navigationBarTitleText: '通知',
  },
}
</route>

<template>
    <z-paging ref="paging" v-model="list" @query="queryList" safe-area-inset-bottom>
        <view class="paging_cont">
            <wd-swipe-action v-for="obj, index in list" :key="index" style="margin-bottom:20rpx;">
                <wd-badge :is-dot="!obj.read" style="width:100%;">
                    <item @click="goTo(`/pages/my/notice/detail?id=${obj.id}`)" :title="obj.title"
                        rightIcon="arrow-right" padding="30rpx 20rpx" style="margin-bottom:0;">
                        <text style="font-size:28rpx;color:#666;">{{ obj.created_at }}</text>
                    </item>
                </wd-badge>
                <template #right>
                    <view class="button" style="background:#FF5A6A;" @click="del(obj)">删除</view>
                </template>
            </wd-swipe-action>
        </view>
    </z-paging>
</template>

<script lang="ts" setup>
import { http } from '@/utils/http';
import { goTo } from '@/utils/url';
import { useMessage } from 'wot-design-uni';
const message = useMessage()
const list = ref<any>([])
const paging = ref(null)
function queryList(page: number, page_size: number) {
    http.get('/member/user/user_notice_me', { page: page, page_size: page_size }).then((res: any) => {
        if (res.code === 200) {
            paging.value.complete(res.data.data);
        }
    })
}
onShow(() => {
    if (paging.value) paging.value.reload();
})

// 删除
function del(obj: any) {
    message.confirm({ title: '确定删除吗' }).then(() => {
        http.put('/member/user/user_notice_me', { id: obj.id, type: "delete_user_id" }).then((res: any) => {
            if (res.code === 200) {
                uni.showToast({ title: "删除完成", icon: "none" })
                paging.value.reload();
            } else {
                uni.showToast({ title: "删除失败", icon: "none" })
            }
        })
    }).catch(() => { })
}
</script>

<style scoped>
:deep(.wd-badge__content.is-dot) {
    transform: translateY(0%) translateX(0%);
}
</style>